/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package srm;

/**
 *
 * @author Wei Chen <acee06.weichen@gmail.com>
 */
import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;

public class AlphabetPath {

    public String doesItExist(String[] letterMaze) {
        // search 'A' at first
        int xA = 0, yA = 0;
        for (int i = 0; i < letterMaze.length; i++) {
            if (letterMaze[i].contains("A")) {
                xA = i;
                yA = letterMaze[i].indexOf("A");
                break;
            }
        }

        char search = 'B';

        while (search <= 'Z') {
            boolean find = false;
            if (yA > 0 && letterMaze[xA].charAt(yA - 1) == search) {
                yA = yA - 1;
                find = true;
            }
            else if (xA > 0 && letterMaze[xA - 1].charAt(yA) == search) {
                xA = xA - 1;
                find = true;
            }
            else if (yA + 1 < letterMaze[xA].length() && letterMaze[xA].charAt(yA + 1) == search) {
                yA = yA + 1;
                find = true;
            }
            else if (xA + 1 < letterMaze.length && letterMaze[xA + 1].charAt(yA) == search) {
                xA = xA + 1;
                find = true;
            }

            if (!find) {
                return "NO";
            }

            search++;
        }

        return "YES";
    }
}
